//
//  UIColor+Ext.m
//  WDPubLib
//
//  Created by wujianrong on 16/4/11.
//  Copyright © 2016年 wanda. All rights reserved.
//

#import "UIColor+wdice.h"

@implementation UIColor(wdice)

+(UIColor*)iceColorWithIntValue:(unsigned int)value
{
    unsigned int R = value >> 16;
    R = R & 0x000000FF;
    unsigned int G = value >> 8;
    G = G & 0x000000FF;
    
    unsigned int B = value & 0x000000FF;
    
    
    return [UIColor colorWithRed:((float) R / 255.0f)
                           green:((float) G / 255.0f)
                            blue:((float) B / 255.0f)
                           alpha:1.0f];
}

+(UIImage*)iceImageWithColor: (UIColor*) color
{
    CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}

+ (UIColor *) iceFromHexRGB:(NSString *) inColorString
{
    UIColor *result = nil;
    unsigned int colorCode = 0;
    unsigned char redByte, greenByte, blueByte;
    
    if (nil != inColorString)
    {
        NSScanner *scanner = [NSScanner scannerWithString:inColorString];
        (void) [scanner scanHexInt:&colorCode]; // ignore error
    }
    redByte = (unsigned char) (colorCode >> 16);
    greenByte = (unsigned char) (colorCode >> 8);
    blueByte = (unsigned char) (colorCode); // masks off high bits
    result = [UIColor
              colorWithRed: (float)redByte / 0xff
              green: (float)greenByte/ 0xff
              blue: (float)blueByte / 0xff
              alpha:1.0];
    return result;
}
@end
